from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import Qt
import sys


class QLineEditDemo(QWidget):
    def __init__(self):
        super(QLineEditDemo, self).__init__()
        self.edit1 = QPlainTextEdit()
        self.initUI()

    def initUI(self):
        self.edit1.setPlainText('老傻逼田九老傻逼田九')
        self.edit1.cursorPositionChanged.connect(self.cursorChanged)
        self.edit1.appendHtml(
            "<font color=#55aaff size=4>{text}</font>")
        print(self.edit1.toPlainText())

        formLayout = QFormLayout()
        formLayout.addRow('整数校验', self.edit1)
        self.setLayout(formLayout)
        self.setWindowTitle('QLineEdit综合案例')

    def cursorChanged(self):
        textCursor = self.edit1.textCursor()
        dq = textCursor.selection()
        print('QTextDocumentFragment ', dq.toPlainText())
        # textCursor = self.edit1.textCursor()
        # print('selectedText: ', textCursor.selectedText())
        ...


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QLineEditDemo()
    main.show()
    sys.exit(app.exec())
